package org.ztr.yanai.blog.exception;

import lombok.Getter;

/**
 * @Author: ZhaoTR
 * @Date: Created in 2025/11/22 14:30
 * @Description: 错误码枚举，统一管理系统错误码和错误信息
 * @Version: 1.0
 */
@Getter
public enum ErrorCode {

    // 通用错误码 1xxx
    SUCCESS(200, "操作成功"),
    SYSTEM_ERROR(1000, "系统错误"),
    PARAM_ERROR(1001, "参数错误"),
    PARAM_MISSING(1002, "参数缺失"),
    PARAM_TYPE_ERROR(1003, "参数类型错误"),
    OPERATION_FAILED(1004, "操作失败"),
    
    // 认证授权错误 2xxx
    UNAUTHORIZED(2000, "未登录或登录已过期"),
    ACCESS_DENIED(2001, "权限不足"),
    TOKEN_INVALID(2002, "Token无效"),
    TOKEN_EXPIRED(2003, "Token已过期"),
    LOGIN_FAILED(2004, "登录失败"),
    PASSWORD_ERROR(2005, "密码错误"),
    
    // 用户相关错误 3xxx
    USER_NOT_FOUND(3000, "用户不存在"),
    USER_ALREADY_EXISTS(3001, "用户已存在"),
    USER_DISABLED(3002, "用户已被禁用"),
    USERNAME_ALREADY_EXISTS(3003, "用户名已存在"),
    EMAIL_ALREADY_EXISTS(3004, "邮箱已被注册"),
    
    // 文章相关错误 4xxx
    POST_NOT_FOUND(4000, "文章不存在"),
    POST_ALREADY_EXISTS(4001, "文章已存在"),
    POST_TITLE_EMPTY(4002, "文章标题不能为空"),
    POST_CONTENT_EMPTY(4003, "文章内容不能为空"),
    POST_NOT_PUBLISHED(4004, "文章未发布"),
    
    // 评论相关错误 5xxx
    COMMENT_NOT_FOUND(5000, "评论不存在"),
    COMMENT_CONTENT_EMPTY(5001, "评论内容不能为空"),
    
    // 分类相关错误 6xxx
    CATEGORY_NOT_FOUND(6000, "分类不存在"),
    CATEGORY_ALREADY_EXISTS(6001, "分类已存在"),
    CATEGORY_HAS_POSTS(6002, "分类下存在文章，无法删除"),
    
    // 标签相关错误 7xxx
    TAG_NOT_FOUND(7000, "标签不存在"),
    TAG_ALREADY_EXISTS(7001, "标签已存在"),
    
    // 文件相关错误 8xxx
    FILE_UPLOAD_FAILED(8000, "文件上传失败"),
    FILE_TYPE_NOT_ALLOWED(8001, "文件类型不允许"),
    FILE_SIZE_EXCEEDED(8002, "文件大小超出限制"),
    FILE_NOT_FOUND(8003, "文件不存在"),
    
    // 数据库相关错误 9xxx
    DATABASE_ERROR(9000, "数据库错误"),
    DATA_NOT_FOUND(9001, "数据不存在"),
    DATA_ALREADY_EXISTS(9002, "数据已存在"),
    DUPLICATE_KEY(9003, "数据重复");

    private final int code;
    private final String message;

    ErrorCode(int code, String message) {
        this.code = code;
        this.message = message;
    }
}
